package QianFeng08.RelationshipDemo;
/**
 * 对象的一对多的关系
 **/
public class OneToMany {
    public static void main(String[] args) {
        Teacher t1 = new Teacher("张老师", 18, "男");
        Student s1 = new Student("大神", 40);
        Student s2 = new Student("大佬", 32);
        Student s3 = new Student("高手", 25);

        //关联关系
        t1.getStudents().add(s1);
        t1.getStudents().add(s2);
        t1.getStudents().add(s3);

        s1.setTeacher(t1);
        s2.setTeacher(t1);
        s3.setTeacher(t1);

        print(t1);
    }

    private static void print(Teacher t1) {
        System.out.println(t1.getName());
        for (Student student : t1.getStudents()) {
            System.out.println(student);
        }
    }
}
